package IOFlow.practice;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

//练习5  方法1
public class FiveOne {
    public static void main(String[] args) throws IOException {
        //排序
        /*
        对出师表进行排序

        F:\Java(IJ)\JavaCase\src\IOFlow\Test.txt
         */

        BufferedReader br=new BufferedReader(new FileReader("JavaCase\\src\\IOFlow\\Test.txt"));
        String line;
        ArrayList<String> list=new ArrayList<>();
        while ((line=br.readLine())!=null){
//            System.out.println(br);
            list.add(line);
        }
//        System.out.println(list);
        br.close();


        //排序
        //排序规则:按照每一行前面的序列号进行排序
        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                int i1=Integer.parseInt(o1.split("\\.")[0]);
                int i2=Integer.parseInt(o2.split("\\.")[0]);
                return i1-i2;
            }
        });
        System.out.println(list);

        //写出
        BufferedWriter bw=new BufferedWriter(new FileWriter("JavaCase\\Test.txt"));
        for (String s : list) {
            bw.write(s);
            bw.newLine();
        }
        bw.close();
    }
}
